package com.cxq.search;

public class BinarySearchDemo {
    public static void main(String[] args) {
        int[] arr = {0,1,2,3,4,5,6,7,8,9,10};
        int index = binarySearch(arr,11);
        System.out.println(index);
    }


    public static int binarySearch(int[] array,int value){
        int low = 0;
        int high = array.length-1;
        int mid=-1;
        while(low <= high){
            mid = (low+high)/2;
            if(value == array[mid]) return mid;
            else if(value < array[mid]) high = mid-1;
            else low = mid+1;
        }
        return -1;
    }
}
